ASP.NET MVC Route Contraints with {ID}-{Slug} Format
Posted
by TimLeung
on Stack Overflow
See other posts from Stack Overflow
or by TimLeung
Published on 2010-04-02T17:35:21Z
Indexed on
2010/04/02
17:53 UTC
Read the original article
Hit count: 429
I have a route like following, ideally I would like it to match:
domain.com/layout/1-slug-is-the-name-of-the-page
routes.MapRoute(
"Layout", // Route name
"layout/{id}-{slug}", // URL with parameters
new { controller = "Home", action = "Index", id = @"\d+$" }
);
But when I hit the url, I am keep on getting this exception:
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32)' in ....
The above route will match the following though:
domain.com/layout/1-slug or domain.com/layout/1-slug_permalink
Seems like the hyphen that separates the ID from the Slug is causing issues.
© Stack Overflow or respective owner